package com.eric.rabbitmq.work.fair;

import com.eric.rabbitmq.utils.RabbitMqUtils;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.MessageProperties;

import java.util.Scanner;

//消息手动应答不丢失，放回队列重新消费
public class Task2 {
    public static final String task_queue_name = "ack_queue";

    public static void main(String[] args) throws Exception {

        Channel channel = RabbitMqUtils.getChannel();
        //开启发布确认

        //生成队列
        boolean durable = true;   //队列持久化
        channel.queueDeclare(task_queue_name, durable, false, false, null);
        System.out.println("创建队列" + task_queue_name + "完成");

        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String message = scanner.next();
            //MessageProperties.PERSISTENT_TEXT_PLAIN 消息持久化
            channel.basicPublish("", task_queue_name, MessageProperties.PERSISTENT_TEXT_PLAIN, message.getBytes("UTF-8"));
            System.out.println("消息发送完毕" + message);
        }
    }
}
